using System;
using System.Xml.Linq;

namespace StickyNotesPrinter.Core
{
    public static class XElementExtension
    {
        public static TValueOfType GetElementAs<TValueOfType>(this XElement element, string name)
        {
            var requestedElement = element.Element(name);
            if (requestedElement == null) return default(TValueOfType);
            return (TValueOfType)Convert.ChangeType(requestedElement.Value,typeof(TValueOfType));
        }
        public static TValueOfType GetAttrributeAs<TValueOfType>(this XElement element, string name)
        {
            var attribute = element.Attribute(name);
            if (attribute == null) return default(TValueOfType);
            return (TValueOfType)Convert.ChangeType(attribute.Value, typeof(TValueOfType));
        }
    }
}